<?php
/**
 * @filesource:				    ServiceRequestAction.class.php
 * @desc:						殡仪服务管理模块
 * 
 * @author:						shenyaqing
 * @copyright:					hou.yining@gmail.com
 * @date:						2011-05-19
 */
class ServiceRequestAction extends CommonAction{
	public function index(){
		$crumb_info = array(
			array('uri' => '__URL__', 'title' => L('service_request_manage'), 'sort' => C('CRUMB_LAST')),
		);
		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(
			array('uri' => '__URL__/add', 'title' => L('add_service_request')),
		);
		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);
		
		parent::index();
	}
	public function add(){
		$crumb_info = array(
			array('uri' => '__URL__', 'title' => L('service_request_manage'), 'sort' => C('CRUMB_DEFAULT')),
			array('uri' => '__URL__/add', 'title' => L('add_service_request'), 'sort' => C('CRUMB_LAST')),
		);
		
		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(
			array('uri' => '__URL__/index', 'title' => L('list_service_request')),
			);
		
		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);
		
		//查询殡仪服务类型
		$servicetype = new ServiceTypeModel();
		$type = $servicetype->getField('id,name');
	   //生成单据编号
		$service = new ServiceRequestModel();
		$info = $service->order('id desc')->limit(1,1)->find();
		$request_id = 'BYFW'.date('Ymd',time()).substr('10000000'+$info[id]+1,1);
		
		$this->assign('request_id',$request_id);
		$this->assign('servicetype',$type);
		$this->display();
	}
	public function edit(){
		$crumb_info = array(
			array('uri' => '__URL__', 'title' => L('service_request_manage'), 'sort' => C('CRUMB_DEFAULT')),
			array('uri' => '__URL__/edit/id/' . $_REQUEST['id'], 'title' => L('edit_service_request'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_info);
		$this->_action_link = array(
			array('uri' => '__URL__/index', 'title' => L('list_service_request')),
			);
		
		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);
		
		$servicetype = new ServiceTypeModel();
		$type = $servicetype->getField('id,name');
		$this->assign('servicetype',$type);
//		$stelecreate = new SteleCreateRequestModel();
//		$id = $_REQUEST [$stelecreate->getPk ()];
//		$vo = $stelecreate->where("id='$id'")->select();
//		$this->assign('list',$vo);
		parent::edit();
	}
	public function search(){
		if(!empty($_POST['request_id'])){
			$where['request_id'] = $_POST['request_id'];
		}
		if(!empty($_POST['dead'])){
			$where['dead_id'] = $_POST['dead'];
		}
		if(!empty($_POST['graveyard_id'])){
			$where['graveyard_id'] = $_POST['graveyard_id'];
		}
		if(!empty($_POST['creater_name'])){
			$where['creater_name'] = $_POST['creater_name'];
		}
		if(!empty($_POST['charge_person_id'])){
			$where['charge_person_id'] = $_POST['charge_person_id'];
		}
		$service = new ServiceRequestModel();
		$a = $service->where($where)->select();
		$this->assign('list',$a);
		$this->display('index');
		
	}
	public function view(){
		$name=$this->getActionName();
		$model = M ( $name );
		$id = $_REQUEST [$model->getPk ()];
		$info = new ServiceRequestModel();
		$list = $info->getInfo($id);

		$this->assign('list',$list);
		$this->display();
	}
//	public function delete() {
//		//删除指定记录
//		$name=$this->getActionName();
//		$model = M ($name);
//		if (! empty ( $model )) {
//			$pk = $model->getPk ();
//			$id = $_REQUEST [$pk];
//			if (isset ( $id )) {
//				$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
//				//放入回收站
//				$list=$model->where ( $condition )->setField ( 'status', - 1 );
//				if ($list!==false) {
//					$this->success ('删除成功！' );
//				} else {
//					$this->error ('删除失败！');
//				}
//			} else {
//				$this->error ( '非法操作' );
//			}
//		}
//	}
}
?>
